package com.ciwong.epaper.modules.scan.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.ciwong.epaper.R;
import com.ciwong.epaper.modules.epaper.bean.ModuleInfo;
import com.ciwong.epaper.util.download.DownLoadInfo;
import com.ciwong.epaper.util.download.DownloadStatus;
import com.ciwong.epaper.util.download.ProgressCircle;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by young on 2017/11/22.
 * preview  and  new type  scan
 *
 */

public class NewQrDetailAdapter  extends android.widget.BaseAdapter {

    private List<DownLoadInfo> downLoadInfos = new ArrayList<>();
    private LayoutInflater inflater;

    public NewQrDetailAdapter(Context context,List<DownLoadInfo> downLoadInfos){
        inflater=LayoutInflater.from(context);
        this.downLoadInfos=downLoadInfos;
    }

    public void  updateData(List<DownLoadInfo> s){
        this.downLoadInfos=s;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return downLoadInfos.size();
    }

    @Override
    public Object getItem(int i) {
        return downLoadInfos.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        try{
            if (view == null)
            {
                view = inflater.inflate(R.layout.adapter_content_list_item2, null);
            }

            TextView resource_name = (TextView) view.findViewById(R.id.resource_name);
            TextView tx_module_name = (TextView) view.findViewById(R.id.tx_module_name);
            ImageView img_module_type= (ImageView) view.findViewById(R.id.img_module_type);
            ProgressCircle progressCircle = (ProgressCircle) view.findViewById(R.id.directory_item_min_pb);
            ImageView imageView_download = (ImageView) view.findViewById(R.id.item_iocn);

            if (i < downLoadInfos.size()) {
                resource_name.setText(downLoadInfos.get(i).getResourceName());
                tx_module_name.setText(downLoadInfos.get(i).getModuleName());


                switch (Integer.parseInt(downLoadInfos.get(i).getModuleId()))
                {

                    // 同步测试
                    case ModuleInfo.ModuleInfoId.MODULE_ID_TEST:
                        img_module_type.setImageResource(R.mipmap.module_type_test);
                        break;
                    // 时文
                    case ModuleInfo.ModuleInfoId.MODULE_ID_ESSAY:
                        img_module_type.setImageResource(R.mipmap.module_type_essay);
                        break;
                    //同步训练
                    case ModuleInfo.ModuleInfoId.MODULE_ID_TRAIN:
                        img_module_type.setImageResource(R.mipmap.module_type_train);
                        break;
                    // 同步跟读
                    case ModuleInfo.ModuleInfoId.MODULE_ID_REPEAT:
                        img_module_type.setImageResource(R.mipmap.module_type_repeat);
                        break;
                    // 听说模考
                    case ModuleInfo.ModuleInfoId.MODULE_ID_LISTEN_SPEAK_EXAM:
                        img_module_type.setImageResource(R.mipmap.module_type_listen_speak_exam);
                        break;
                    // 微技能训练
                    case ModuleInfo.ModuleInfoId.MODULE_ID_MICRO_SKILLS:
                        img_module_type.setImageResource(R.mipmap.module_type_micro_skills);
                        break;
                    // 报听写
                    case ModuleInfo.ModuleInfoId.MODULE_ID_DICTATION:
                        img_module_type.setImageResource(R.mipmap.module_type_dictation);
                        break;
                    // 视频讲解
                    case ModuleInfo.ModuleInfoId.MODULE_ID_VIDEO_EXPLAIN:
                    case ModuleInfo.ModuleInfoId.MODULE_ID_VIDEO_EXPLAIN_NEW:
                        img_module_type.setImageResource(R.mipmap.module_type_video);
                        break;
                    // 在线作答
                    case ModuleInfo.ModuleInfoId.MODULE_ID_ONLINE_ANSWER:
                        img_module_type.setImageResource(R.mipmap.module_type_online_answer);
                        break;
                    // 互动教程
                    case ModuleInfo.ModuleInfoId.MODULE_ID_INTERACTIVE_TUTORIAL:
                        img_module_type.setImageResource(R.mipmap.module_type_interactive_tutorial);
                        break;
                }

                if (downLoadInfos.get(i) != null) {

                    if (ModuleInfo.ModuleInfoId.MODULE_ID_ESSAY == Integer.valueOf(downLoadInfos.get(i).getModuleId())){
                            Hoder hoder = new Hoder();
                            hoder.imageView_download = imageView_download;
                    }else {
                        switch (downLoadInfos.get(i).getStatus()) {
                            case DownloadStatus.STATUS_COMPLETED:
                            case DownloadStatus.STATUS_PAUSE:
                            case DownloadStatus.STATUS_FAILED:
                            case DownloadStatus.STATUS_FAILED_SDISFULL:
                            case DownloadStatus.STATUS_FAILED_UNZIP:
                            case DownloadStatus.STATUS_DOWNLOADING:

                                if (downLoadInfos.get(i) != null) {
                                    Hoder hoder = new Hoder();
                                    hoder.imageView_download = imageView_download;
                                }

                                break;
                            default:
                                break;
                        }
                    }



                }else {

                    Log.d("DownLoadInfos", "#######info == null##########");

                }

            }

            return view;
        }catch (Exception e){
            e.getStackTrace();
        }
        return null;
    }

    private class Hoder {
        public ImageView imageView_download;
    }




}
